﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;

namespace AutoMeasureV2._1
{
    /// <summary>
    /// tableUC.xaml 的交互逻辑
    /// </summary>
    public partial class tableUC : UserControl
    {
        public tableUC()
        {
            InitializeComponent();
        }

        private Dictionary<string, DataTable> rdiTable = new Dictionary<string, DataTable>();
        public Dictionary<string, DataTable> RdiTable
        {
            get { return rdiTable; }
            set { rdiTable = value; }
        }

        private fileHandle handle;
        public fileHandle Handle
        {
            set
            {
                RdiTable.Clear();
                handle = value;

                foreach (var item in value.TableMessage)
                {
                    DataTable tb = new DataTable();
                    for (int i = 0; i < item.Value.Count; i++)
                    {
                        tb.Columns.Add(item.Value[i].tableColumn);
                    }

                    for (int i = 0; i < item.Value[1].tableRow.Count; i++)
                    {
                        DataRow dr = tb.NewRow();
                        for (int j = 0; j < item.Value.Count; j++)
                        {
                            dr[j] = item.Value[j].tableRow[i]; 
                        }
                        tb.Rows.Add(dr);
                    }

                    RdiTable.Add(item.Key,tb); 
                }
            }
        }

        public void setName(string tableName)
        {
            foreach (var item in RdiTable)
            {
                if (item.Key == tableName)
                {
                    dataGrid1.ItemsSource = item.Value.DefaultView;
                    break;
                }
            }
        }



    }
}
